#!/bin/sh

# 环境变量设置
source ~/.vis_profile

# start services.
start()
{
    # 升级
    ${VIS_ROOT_PATH}/manager/script/upgrade.sh
    
    # 启动
    cd ${VIS_ROOT_PATH}/nginx;./init-nginx.sh start &
    
    cd ${VIS_ROOT_PATH}/srs;./init-srs.sh start &
    
    cd ${VIS_ROOT_PATH}/manager;./init-manager.sh start &
}

stop()
{
    # 停止
    cd ${VIS_ROOT_PATH}/nginx;./init-nginx.sh stop &
    
    cd ${VIS_ROOT_PATH}/srs;./init-srs.sh stop &
    
    cd ${VIS_ROOT_PATH}/manager;./init-manager.sh stop &
}

RETVAL=0
# execute parameter:
#  @$1  start|stop|restart|...
#  @$2  shell file name.
execute()
{
    case "$1" in
        start)
            start
        ;;
        
        stop)
            stop
        ;;
        
        restart)
            stop
            sleep 3
            start
        ;;
        
        *)
            echo $"Usage: $2 {start|stop|restart|reload|status}"
            RETVAL=1
            exit $RETVAL
    esac
}

# execute shell file.
execute "$1" "$0"

RETVAL=$?

exit $RETVAL
